package com.yishu.Dao;

import com.yishu.entity.Admin;
import com.yishu.util.DBConnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class AdminDao {

    DBConnection dbConnection = new DBConnection();

    /**
     * 管理员登录入口
     * @param connection
     * @param admin
     * @return
     * @throws Exception
     */
    public Admin adminLogin(Connection connection,Admin admin) throws Exception {
        Admin resultAdmin = null;
        String sql = "select * from t_admins where adminName='"+admin.getAdminName()+"'and password='"+admin.getPassword()+"'";
        connection = dbConnection.getCon();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);

        if(resultSet.next()) {
            resultAdmin = new Admin();
            resultAdmin.setAdminId(resultSet.getInt("adminId"));
            resultAdmin.setAdminName(resultSet.getString("adminName"));
            resultAdmin.setPassword(resultSet.getString("password"));
        }
        return resultAdmin;
    }
}
